<template>
	<view class="main">
		<view class="head">
			<img class="headbg"
				src="https://www.ysrs.xyz/apiI/ll/file/preview/1743073131604ff80808195d597d90195d7413c540002.png" alt="" />
			<view class="user" v-if="userInfo.id">
				<view class="userp">
					<img
						:src="userInfo.avatarUrl||'https://www.ysrs.xyz/apiI/ll/file/preview/1743090725920ff80808195d597d90195d84db4200013.png'"
						alt="" />
					<button class="chooseAvatar" open-type="chooseAvatar" @chooseavatar="onChooseavatar"></button>
				</view>
				<view class="userc">
					<view class="userci">{{userInfo.mobile || '微信用户HKU812'}}</view>
				</view>
			</view>
			<view class="toLogin" v-else @click="toLogin">
				<view>去登录</view>
			</view>

			<view class="changeRole" @click="changeRole" v-if="!userInfo.bindStatus && userInfo.id">
				<img src="https://www.ysrs.xyz/apiI/ll/file/preview/1743419281186ff80808195d597d90195ebe30f220018.png" alt="" />
				切换至{{userInfo.currentVersion == 1 ?'医生':'用户'}}端
			</view>
			<view class="toRegist" v-if="userInfo.bindStatus && userInfo.id" @click="toRegist">
				<img src="https://www.ysrs.xyz/apiI/ll/file/preview/1743418988714ff80808195d597d90195ebde98aa0017.png" alt="" />
				医生认证
			</view>
		</view>


		<view class="mainV" v-if="userInfo.currentVersion == 1 &&userInfo.id">
			<view class="pv">
				<view class="pvt">
					<view class="pvti" v-for="(i,o) in pvList " :key="o" @click="openPath(i.path)">
						<img :src="i.icon" alt="" />
						<text>{{i.name}}</text>
					</view>
				</view>
				<view class="pvc">
					<uv-cell-group>
						<uv-cell icon="" :cellStyle="{'padding':'30rpx'}" title="医院介绍" :isLink="true"
							@click="openPath('/pages/index/info')">
							<template v-slot:icon>
								<uv-icon size="36rpx" color="#1dac85" name="home"></uv-icon>
							</template>
						</uv-cell>
						<uv-cell icon="" :cellStyle="{'padding':'30rpx'}" title="我的资料" :isLink="true" v-if="userInfo.role !== 0"
							@click="openMyInfo">
							<template v-slot:icon>
								<uv-icon size="36rpx" color="#1dac85" name="account"></uv-icon>
							</template>
						</uv-cell>
						<uv-cell icon="" :cellStyle="{'padding':'30rpx'}" title="联系客服" :isLink="true">
							<template v-slot:icon>
								<uv-icon size="36rpx" color="#1dac85" name="kefu-ermai"></uv-icon>
							</template>
						</uv-cell>
						<uv-cell icon="" :cellStyle="{'padding':'30rpx'}" title="问题反馈" :isLink="true" @click="openProblemFeedback">
							<template v-slot:icon>
								<uv-icon size="36rpx" color="#1dac85" name="file-text"></uv-icon>
							</template>
						</uv-cell>
						<uv-cell icon="" :cellStyle="{'padding':'30rpx'}" title="账号绑定" :isLink="true" @click="openlogin">
							<template v-slot:icon>
								<uv-icon size="36rpx" color="#1dac85" name="attach"></uv-icon>
							</template>
						</uv-cell>
						<uv-cell :cellStyle="{'padding':'30rpx'}" icon="" title="清除缓存" :isLink="true" @click="clearStorage">
							<template v-slot:icon>
								<uv-icon size="36rpx" color="#1dac85" name="coupon"></uv-icon>
							</template>
						</uv-cell>

					</uv-cell-group>
				</view>
			</view>
		</view>

		<view class="mainV" v-if="userInfo.currentVersion !== 1 &&userInfo.id">
			<view class="maind">
				<view class="md">
					<view class="mdi">
						<img :style="{backgroundColor:doctorInfo.img?'':'#eee'}"
							:src="doctorInfo.img||'https://www.ysrs.xyz/apiI/ll/file/preview/1743090725920ff80808195d597d90195d84db4200013.png'" />
					</view>
					<view class="mdr">
						<view class="mdrt">{{doctorInfo.name}}<text>{{doctorInfo.zhicheng}}</text></view>
						<view class="mdrb">{{doctorInfo.keshi}}</view>
					</view>
				</view>
			</view>
			<view class="maingh">您好！您的今日排班数：<text>{{doctorInfo.paiban ==0 ? '暂无排班':doctorInfo.guahao}}</text></view>
			<view class="mainghs">
				<view class="headbgsi">
					<view class="headbgsit">预约挂号</view>
					<view class="headbgsin">{{doctorInfo.guahao}}</view>
				</view>
				<view class="headbgsi">
					<view class="headbgsit">远程问诊</view>
					<view class="headbgsin">{{doctorInfo.xianshang}}</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	import {
		changeRoleApi
	} from '@/api/common.js'

	export default {
		data() {
			return {
				pvList: [{
						name: '就诊人管理',
						icon: 'https://www.ysrs.xyz/apiI/ll/file/preview/1745025401763ff80808195d597d901964b9e83a3006c.png',
						path: '/pages/AddPatient/Patient'
					},
					{
						name: '购药记录',
						icon: 'https://www.ysrs.xyz/apiI/ll/file/preview/1745025367401ff80808195d597d901964b9dfd69006a.png',
						path: ''
					},
					{
						name: '住院通知单',
						icon: 'https://www.ysrs.xyz/apiI/ll/file/preview/1745025347764ff80808195d597d901964b9db0b40069.png',
						path: ''
					},
					{
						name: '我的发票',
						icon: 'https://www.ysrs.xyz/apiI/ll/file/preview/1745025376933ff80808195d597d901964b9e22a5006b.png',
						path: ''
					},
				],
				userInfo: {},
				doctorInfo: {
					name: '张三',
					zhicheng: '主任医生',
					keshi: '肠胃科',
					img: '',
					paiban: 24,
					xianshang: 5,
					guahao: 3,
				},
			}
		},
		onShow() {
			this.userInfo = uni.getStorageSync('userInfo') || null
			console.log(this.userInfo)
		},
		mounted() {

		},
		methods: {
			changeRole() {
				this.userInfo.currentVersion = Number(!Boolean(this.userInfo.currentVersion))
				uni.setStorageSync('userInfo', this.userInfo)
				// changeRoleApi({
				// 	userId: this.userInfo.id
				// }).then(res => {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: res.data.message
				// 	})
				// 	if (res.data.code == 200) {
				// 		uni.setStorageSync('userInfo', res.data.result)
				// 		this.userInfo = res.data.result
				// 		console.log(this.userInfo)
				// 	}
				// })
			},
			onChooseavatar(e) {
				uploadFile(e.detail.avatarUrl).then(res => {
					this.userInfo.avatarUrl = res.message
				})
			},
			toRegist() {
				uni.navigateTo({
					url: '/pages/personal/regist'
				})
			},
			openPath(path) {
				if (!path) {
					uni.showToast({
						title: '敬请期待！',
						duration: 2000,
						icon: 'none'
					})
					return;
				}
				if (!this.userInfo) {
					uni.showToast({
						title: '请登录！',
						duration: 1000,
						icon: 'none'
					})
					return;
				}
				uni.navigateTo({
					url: path
				})
			},
			toLogin() {
				uni.navigateTo({
					url: '/pages/personal/login'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		min-height: 100vh;
		background: linear-gradient(to bottom, #2c9b9433, #fff);

		.head {
			width: 100vw;
			height: 500rpx;
			position: relative;

			.headbg {
				position: absolute;
				z-index: 1;
				opacity: .1;
				width: 100%;
				height: 100%;
			}

			.user {
				position: absolute;
				z-index: 2;
				bottom: 200rpx;
				left: 40rpx;
				display: flex;
				align-items: center;

				.userp {
					border-radius: 50%;
					display: flex;
					background: #fff;
					align-items: center;
					justify-content: center;
					width: 140rpx;
					height: 140rpx;
					position: relative;
					z-index: 2;
					margin-right: 20rpx;
					box-shadow: 0 0 12rpx #ccc;

					img {
						position: relative;
						z-index: 2;
						opacity: 1;
						width: 120rpx;
						height: 120rpx;
						background-color: #fff;
						border-radius: 50%;
						box-shadow: 0 0 12rpx #ccc;
					}

					.chooseAvatar {
						position: absolute;
						width: 120rpx;
						height: 120rpx;
						left: calc(50% - 60rpx);
						top: calc(50% - 60rpx);
						z-index: 99;
						opacity: 0;
					}
				}

				.userc {
					font-size: 34rpx;
					font-weight: bold;
					letter-spacing: 2rpx;
				}
			}

			.toLogin {
				position: absolute;
				z-index: 2;
				bottom: 180rpx;
				left: 60rpx;

				view {
					width: 220rpx;
					height: 64rpx;
					font-size: 33rpx;
					text-align: center;
					line-height: 64rpx;
					border-radius: 12rpx;
					color: #fff;
					background-color: #2c9b94;
					box-shadow: 0 0 12rpx #ccc;
				}
			}

			.toRegist,
			.changeRole {
				position: absolute;
				z-index: 2;
				right: 30rpx;
				bottom: 180rpx;
				display: flex;
				align-items: center;
				background-color: #2c9b94;
				border-radius: 12rpx;
				box-shadow: 0 0 12rpx #2c9b94;
				color: #fff;
				justify-content: center;
				width: 200rpx;
				height: 60rpx;

				img {
					margin-right: 10rpx;
					width: 40rpx;
					height: 40rpx;
				}
			}

			.changeRole {
				width: 260rpx;
			}

		}

		.maint {
			font-weight: bold;
			font-size: 34rpx;
			display: flex;
			align-items: center;
			margin-bottom: 30rpx;

			&:before {
				content: '';
				display: inline-block;
				width: 10rpx;
				border-radius: 4rpx;
				height: 36rpx;
				background-color: #2c9b94;
				margin-right: 20rpx;
			}
		}

		.mainV {
			position: relative;
			z-index: 9;
		}
	}

	.pv {
		width: 660rpx;
		padding: 30rpx;
		background: #FFFFFFaa;
		box-shadow: 0rpx 8rpx 16rpx 0rpx rgba(0, 0, 0, 0.15);
		margin: -150rpx auto 0;
		border-radius: 16rpx;

		.pvt {
			margin: 30rpx 0;
			display: flex;
			align-items: center;
			justify-content: space-around;

			.pvti {
				width: 25%;
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: column;

				img {
					width: 75rpx;
					height: 75rpx;
					margin-bottom: 10rpx;
				}

				text {
					color: #333;
					font-size: 29rpx;
				}
			}
		}
	}

	.maind {
		margin: 20rpx 30rpx 0;
		background-color: #fff;
		padding: 20rpx 30rpx;
		border-radius: 12rpx 12rpx 0 0;

		.md {
			display: flex;
			align-items: center;

			.mdi {
				background-color: #fff;
				border-radius: 50%;
				padding: 6rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-right: 30rpx;

				img {
					width: 140rpx;
					height: 140rpx;
					border-radius: 22rpx;
					border-radius: 50%;
				}
			}

			.mdr {
				.mdrt {
					font-weight: bold;
					margin-bottom: 20rpx;

					text {
						font-weight: normal;
						display: inline-block;
						margin-left: 20rpx;
						color: #666;
					}
				}

				.mdrb {
					color: #444;
				}
			}

		}

	}

	.maingh {
		height: 80rpx;
		// color: #fff;
		background-color: #ffffff88;
		margin: 0 30rpx;
		font-size: 33rpx;
		font-weight: bold;
		display: flex;
		align-items: center;
		justify-content: center;
		letter-spacing: 5rpx;

		text {
			color: #F56C6C;
			text-shadow: 0 0 6rpx #fff;
			font-size: 50rpx;
		}
	}

	.mainghs {
		margin: 0 30rpx 0;
		background-color: #fff;
		padding: 20rpx 30rpx;
		border-radius: 0 0 12rpx 12rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.headbgsi {
			width: 50%;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;

			&:last-of-type {
				border-left: 1px dashed #ddd;
			}

			.headbgsit {}

			.headbgsin {
				color: #2c9b94;
				font-weight: bold;
				font-size: 50rpx;
			}
		}
	}

	::-webkit-scrollbar {
		/*滚动条整体样式*/
		width: 4px;
		/*高宽分别对应横竖滚动条的尺寸*/
		height: 1px;
	}

	::-webkit-scrollbar-thumb {
		/*滚动条里面小方块*/
		border-radius: 10px;
		box-shadow: inset 0 0 5px rgba(97, 184, 179, 0.1);
		background: #2c9b94;
	}

	::-webkit-scrollbar-track {
		/*滚动条里面轨道*/
		box-shadow: inset 0 0 5px rgba(87, 175, 187, 0.1);
		border-radius: 10px;
		background: #ededed;
	}
</style>